layui.use(["element", "layer"], function () {

    //引入所需的模块
    var $ = layui.jquery,
        element = layui.element,
        layer = layui.layer;

    //定义常用元素
    var l_o = $(".left-menu"),
        tab = "top-tab",
        l_m = "left-menu",
        t_m = "top-menu";

    //定义容器高度
    var mainHeight = $(window).height() - 60 - 41- 5;
    
    //
    element.on("nav(" + t_m + ")", function (data) {
        l_o.hide().eq(data.index()).show()
    });

    //顶级菜单 点击所有展开
    l_o.on("click", "li", function () {
        $(this).siblings().removeClass("layui-nav-itemed")
    });

    //左侧菜单点击
    element.on("nav(" + l_m + ")", function (data) {

        //获取所有下级子菜单
        var a_t = data.children("a"),
            id = a_t.data("id"),
            url = a_t.data("url"),
            title = a_t.html(),
            length = $(".layui-tab-title").children("li[lay-id='" + id + "']").length;

        //如果没有打开tab标签,就创建窗口
        if (!length) {
            var iframe = '<iframe src="' + url + '" style="height:' + mainHeight + 'px;"></iframe>';
            element.tabAdd(tab, {
                title: title,
                content: iframe,
                id: id
            })
        }

        //如果已经存在tab标签,直接切换tab
        element.tabChange(tab, id)
    });

    l_o.children("li:first").children("a:first").click();

    $(".menu-flexible").click(function () {
        $(".left-menu-all").toggle();
        $(".layui-body,.layui-footer").css("left", ($(".left-menu-all").is(":hidden")) ? "0" : "200px")
    });

    $(".layui-tab-button").on("click", "a", function () {
        var iframe = $(".layui-tab-content").find(".layui-show iframe");
        iframe.attr("src", iframe.attr("src"))
    });


    $('#change_psw').on('click',function(){
        // 修改密码
        layer.open({
            type:2
            ,area:['450px', '320px']
            ,title:"修改密码"
            ,content: '/user/change'
        });
    });


});